﻿using CubicFWNet.Application.SystemManager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PagedList;
using CubicFWNet.Common;
using CubicFWNet.Data.Models;

namespace CubicFWNet.Mvc.Controllers
{
    public class LearningTypeController : ControllerBase
    {
        private NewsTypeApp _newstypeApp;
        // GET: LearningType
         public LearningTypeController()
        {
            _newstypeApp = new NewsTypeApp();
        }
        public ActionResult Index(int page = 1)
        {
            return View(_newstypeApp.GetLearningList().ToPagedList(page, 10));
        }
        [HttpPost]
        [HandlerAjaxOnly]
        public string Add(NewsType newstype)
        {
            newstype.Class = 2;
            newstype.Status = true;
            _newstypeApp.AddOrUpdate(newstype);
            return Result.ToJson();
        }

        public ActionResult GetFormJson(Guid id)
        {
            var data = _newstypeApp.GetForm(id);
            return Content(data.ToJson());
        }

        [HttpPost]
        [HandlerAjaxOnly]
        public string Delete(Guid id)
        {

            if (_newstypeApp.Delete(id) == -404)
            {
                Result.Status = "error";
                Result.Message = "未找到该数据";
            }
            return Result.ToJson();
        }
    }
}